package com.dianning.web.action.user;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.*;

import com.dianning.bean.Company;
import com.dianning.bean.Parameter;
import com.dianning.bean.Resume;
import com.dianning.bean.UserDetail;
import com.dianning.bean.UserInfo;
import com.dianning.bean.Visitor;
import com.dianning.comm.Constant;
import com.dianning.comm.OrderObj;
import com.dianning.comm.Util;
import com.dianning.service.InfoService;
import com.dianning.service.ParameterService;
import com.dianning.service.UserInfoService;
import com.dianning.service.VisitorService;
import com.dianning.service.web.PageList;
import com.dianning.service.web.Pages;
import com.dianning.web.action.BaseAction;
import com.dianning.web.interceptor.UserSessionAware;
import com.dianning.web.servlet.UserSession;
import com.dianning.web.ui.OptionsLong;

public class CompanyAction extends BaseAction implements UserSessionAware{

	private static final Log logger = LogFactory.getLog(CompanyAction.class);
	
	private UserInfoService userInfoService;
	private ParameterService parameterService;

	public UserInfoService getUserInfoService() {
		return userInfoService;
	}

	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	
	public ParameterService getParameterService() {
		return parameterService;
	}

	public void setParameterService(ParameterService parameterService) {
		this.parameterService = parameterService;
	}
	
	private List companyTradeList = new ArrayList();
	private List companyTypeList = new ArrayList();
	private List companySizeList = new ArrayList();
	

	public List getCompanyTradeList() {
		return companyTradeList;
	}

	public void setCompanyTradeList(List companyTradeList) {
		this.companyTradeList = companyTradeList;
	}

	public List getCompanyTypeList() {
		return companyTypeList;
	}

	public void setCompanyTypeList(List companyTypeList) {
		this.companyTypeList = companyTypeList;
	}

	public List getCompanySizeList() {
		return companySizeList;
	}

	public void setCompanySizeList(List companySizeList) {
		this.companySizeList = companySizeList;
	}
	
	private void setCompanyTradeListValues(){
		List l = this.getParameterService().findParameters("companyTrade", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			companyTradeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setCompanyTypeListValues(){
		List l = this.getParameterService().findParameters("companyType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			companyTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setCompanySizeListValues(){
		List l = this.getParameterService().findParameters("companySize", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			companySizeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	
	private void initValues(){
		setCompanyTradeListValues();
		setCompanyTypeListValues();
		setCompanySizeListValues();
	}

	private UserSession userSession;

	public UserSession getUserSession() {
		return userSession;
	}

	public void setUserSession(UserSession userSession) {
		this.userSession = userSession;
	}
	
	private Company company;

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}
	
	private String domain = Constant.DOMAIN;
	private String companyname;
	private int companyTrade;
	private int companyType;
	private int companySize;
	private String linkman;
	private String tel;
	private String email;
	private String address;
	private String remark;

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}
	
	public String getCompanyname() {
		return companyname;
	}

	public void setCompanyname(String companyname) {
		this.companyname = companyname;
	}

	public int getCompanyTrade() {
		return companyTrade;
	}

	public void setCompanyTrade(int companyTrade) {
		this.companyTrade = companyTrade;
	}

	public int getCompanyType() {
		return companyType;
	}

	public void setCompanyType(int companyType) {
		this.companyType = companyType;
	}

	public int getCompanySize() {
		return companySize;
	}

	public void setCompanySize(int companySize) {
		this.companySize = companySize;
	}

	public String getLinkman() {
		return linkman;
	}

	public void setLinkman(String linkman) {
		this.linkman = linkman;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	
	
	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return ERROR;
		}
	}
	
	public String index(){
		initValues();
		Company c = this.getUserInfoService().findCompanyByUid(userSession.getUid());
		this.companyname = c.getCompanyname();
		this.companyTrade = c.getCompanyTrade();
		this.companyType = c.getCompanyType();
		this.companySize = c.getCompanySize();
		this.linkman = c.getLinkman();
		this.tel = c.getTel();
		this.email = c.getEmail();
		this.address = c.getAddress();
		this.remark = c.getRemark();
		return "index";
	}

	public String save(){
		Company c = this.getUserInfoService().findCompanyByUid(userSession.getUid());
		c.setCompanyname(this.companyname);
		c.setCompanyTrade(this.companyTrade);
		c.setCompanyType(this.companyType);
		c.setCompanySize(this.companySize);
		c.setLinkman(this.linkman);
		c.setTel(this.tel);
		c.setEmail(this.email);
		c.setAddress(this.address);
		c.setRemark(this.remark);
		this.getUserInfoService().updateCompany(c);
		return "save";
	}
	
	public String license(){
		this.setCompany(this.getUserInfoService().findCompanyByUid(userSession.getUid()));
		return "license";
	}


}
